/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BuscadorPedido.java
 *
 * Created on Jan 28, 2011, 4:16:28 PM
 */

package org.ik.Reposteria.SMP.Ventanas.Buscadores;

import java.awt.Dimension;
import java.awt.Toolkit;
import org.ik.Reposteria.SMP.Encapsulados.Pedidos;

/**
 *
 * @author Malkavian
 */
public class BuscadorPedido extends javax.swing.JDialog {

    private TableModelPedido tper;
    Pedidos pedid;
    /** Creates new form BuscadorPedido */
    public BuscadorPedido(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        setTitle("Busqueda Pedidos");
        Dimension d = new Dimension(this.getSize());
        Dimension g = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(g.width/2 - d.width/2,g.height/2 - d.height/2,d.width,d.height);

        initComponents();
        tper = new TableModelPedido(ManejadorPedido.getInstance().getPedidos());
        tablagente.setModel(tper);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tablagente = new javax.swing.JTable();
        sel = new javax.swing.JButton();
        buscar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tnombre = new javax.swing.JTextField();
        tapellido = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        tablagente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tablagente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablagenteMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tablagenteMouseReleased(evt);
            }
        });
        tablagente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tablagenteKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tablagenteKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tablagente);

        sel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        sel.setText("Seleccionar");
        sel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selActionPerformed(evt);
            }
        });

        buscar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        buscar.setText("Buscar");
        buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Cliente");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Dirección");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(buscar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(sel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(tapellido, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sel)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buscar)
                    .addComponent(tnombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tapellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tablagenteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablagenteMouseClicked
        // TODO add your handling code here:
        if(tablagente.getSelectedRow() >= 0)
        {
            pedid = (Pedido) tper.getRow(tablagente.getSelectedRow());
        }
    }//GEN-LAST:event_tablagenteMouseClicked

    private void selActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selActionPerformed
        dispose();
    }//GEN-LAST:event_selActionPerformed

    private void buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarActionPerformed
        // TODO add your handling code here:
        if(tnombre.getText().isEmpty() && tapellido.getText().isEmpty())
            tper = new TableModelPedido(ManejadorPedido.getInstance().getPedidos());
        else
            tper = new TableModelPedido(ManejadorPedido.getInstance().getPedidos(tnombre.getText(), tapellido.getText()));
        tablagente.setModel(tper);

    }//GEN-LAST:event_buscarActionPerformed

    private void tablagenteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablagenteKeyPressed
        if(tablagente.getSelectedRow() >= 0)
        {
            pedid = (Pedido) tper.getRow(tablagente.getSelectedRow());
        }
    }//GEN-LAST:event_tablagenteKeyPressed

    private void tablagenteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablagenteKeyReleased
        if(tablagente.getSelectedRow() >= 0)
        {
            pedid = (Pedido) tper.getRow(tablagente.getSelectedRow());
        }
    }//GEN-LAST:event_tablagenteKeyReleased

    private void tablagenteMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablagenteMouseReleased
        if(tablagente.getSelectedRow() >= 0)
        {
            pedid = (Pedido) tper.getRow(tablagente.getSelectedRow());
        }
    }//GEN-LAST:event_tablagenteMouseReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buscar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton sel;
    private javax.swing.JTable tablagente;
    private javax.swing.JTextField tapellido;
    private javax.swing.JTextField tnombre;
    // End of variables declaration//GEN-END:variables

}
